


use "$temp/hssc_main_result.dta", clear

global wf        m_age m_eduyr m_goodhlth m_pens m_ins
global hb        f_age f_eduyr f_goodhlth f_pens f_ins  
global household pid_c1_gender landrentout transinc hhnetasst

*Table 1
*Sample distribution of each survey wave
***********************************************************************************************
***********************************************************************************************
tab year if sample_child_quantity ==1
tab year if sample_child_quality  ==1

*Table 2
*Descriptive statistics by women's non-farm employment participation status
***********************************************************************************************
***********************************************************************************************
reg numchldtot $wf $hb $household 
outreg2 using table1,sum replace word excel dec(3) 
reg numchldtot $wf $hb $household if treat_it == 1 
outreg2 using table1,sum append word excel dec(3)
reg numchldtot $wf $hb $household if treat_it == 0 
outreg2 using table1,sum append word excel dec(3)

local i = 0
foreach x of varlist numchldtot $wf $hb $household  {
         local i = `i' + 1
         gen var`i'=`x'            
}
mat T = J(15,4,.) 
forvalues i = 1 2 to 15 {
                  ttest var`i',by (treat_it) 
                  mat T[`i',1]= r(mu_2)
				  mat T[`i',2]= r(mu_1)
                  mat T[`i',3]= r(mu_2)-r(mu_1)
                  mat T[`i',4]= r(p)
}
mat rownames T = numchldtot $wf $hb $household 
logout, save(myfile) excel replace: /// 
frmttable using diff_test,statmat(T) replace sdec(3) ctitles (varname, treat, non-treat , Diff, p-value)
drop var*

*Table 3 
*TWFE estimation for the impact of women's non-farm employment on child quantity and quality
***********************************************************************************************
***********************************************************************************************
reghdfe numchldtot   treat_it $wf $hb $household, a(pid_a_m year) vce(robust) keepsingletons
est store model_1
reghdfe cagtest_cn   treat_it $wf $hb $household i.educag numchldtot_nonzero ratboy_hh, a(pid_a_m year) vce(robust) keepsingletons
est store model_2
reghdfe cagtest_math treat_it $wf $hb $household i.educag numchldtot_nonzero ratboy_hh, a(pid_a_m year) vce(robust) keepsingletons
est store model_3
outreg2 [model_*] using table1,replace  word excel  dec(3) alpha(0.01, 0.05, 0.1)  addtext(Year FE, Yes, Individual FE, Yes)  

*Table 7 
*Mechanism analysis for the impacts on child quantity
***********************************************************************************************
***********************************************************************************************
reghdfe m_numferdes     treat_it $wf $hb $household , a(pid_a_m year) vce(robust) keepsingletons
est store model_1
reghdfe m_numsondes     treat_it $wf $hb $household , a(pid_a_m year) vce(robust) keepsingletons
est store model_2
reghdfe familyline      treat_it $wf $hb $household , a(pid_a_m year) vce(robust) keepsingletons
est store model_3
reghdfe m_rate_qm1101   treat_it $wf $hb $household , a(pid_a_m year) vce(robust) keepsingletons
est store model_4
outreg2 [model_*] using table1,replace  word excel  dec(3) alpha(0.01, 0.05, 0.1)  addtext(Year FE, Yes, Individual FE, Yes)  

*Table 8 
*Mechanism analysis for the impacts on child quality
***********************************************************************************************
***********************************************************************************************
reghdfe cdedutotal_exp   treat_it $wf $hb $household i.educag numchldtot_nonzero ratboy_hh if cdedutotal_exp!=0, a(pid_a_m year) vce(robust) keepsingletons
est store model_1
reghdfe m_carechild_hrdy treat_it $wf $hb $household i.educag numchldtot_nonzero ratboy_hh, a(pid_a_m year) vce(robust) keepsingletons
est store model_2
reghdfe rate_wf604m      treat_it $wf $hb $household i.educag numchldtot_nonzero ratboy_hh, a(pid_a_m year) vce(robust) keepsingletons
est store model_3
outreg2 [model_*] using table1,replace  word excel  dec(3) alpha(0.01, 0.05, 0.1)  addtext(Year FE, Yes, Individual FE, Yes)  
























